/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.12
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   标签指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "labeljmpview.h"
#include "ui_labeljmpview.h"
#include "../../programView/programview.h"
#include "progromlistview.h"

LabelJmpView::LabelJmpView(int styleId,QWidget *parent):
    QWidget(parent),
    ui(new Ui::LabelJmpView)
{
    ui->setupUi(this);
    initialDisplayStyle(styleId);
    ui->lineEdit_labelStr->setText("1");




}

void LabelJmpView::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
       ui->LBL_GBox->setGeometry(10,10,430,50);
       ui->LBL_radioButton->setGeometry(20,20,100,20);
       ui->lineEdit_labelStr->setGeometry(130,15,290,30);

       ui->LBL_GBox_2->setGeometry(10,65,430,100);
       ui->lineEdit_labelStr_jump->setGeometry(20,60,400,30);

       ui->groupBox_2->setGeometry(10,170,430,50);

       ui->groupBox_3->setGeometry(10,225,430,80);
       ui->CALL_radioButton->setGeometry(10,20,130,30);
       ui->RUN_radioButton->setGeometry(10,50,130,20);

       ui->note_GBox->setGeometry(10,305,430,50);
       ui->note_lineEdit->setGeometry(20,15,300,30);
       ui->clearNote_Btn->setGeometry(350,15,65,30);

       ui->forward_Btn->setGeometry(10,355,70,40);
       ui->save_Btn->setGeometry(360,355,70,40);
        break;
    default:
        break;
    }
}

void LabelJmpView::updateView()
{
    ui->END_radioButton->setEnabled(false);
    ui->PAUSE_radioButton->setEnabled(false);
    ui->ABORT_radioButton->setEnabled(false);
    ui->CALL_radioButton->setEnabled(false);
    ui->RUN_radioButton->setEnabled(false);
    ui->LBL_radioButton->setEnabled(false);
    ui->JMP_radioButton->setEnabled(false);

    ui->END_radioButton->setChecked(false);
    ui->PAUSE_radioButton->setChecked(false);
    ui->ABORT_radioButton->setChecked(false);
    ui->CALL_radioButton->setChecked(false);
    ui->RUN_radioButton->setChecked(false);
    ui->LBL_radioButton->setChecked(false);
    ui->JMP_radioButton->setChecked(false);
    ui->lineEdit_labelStr->clear();
    ui->lineEdit_labelStr_jump->clear();
    ui->CALLProgram_lineEdit->clear();


    if(EM_LBLJMP_INSTRUCTION_LBL == selectInstructionFlag)
    {
        ui->LBL_radioButton->setEnabled(true);
        ui->LBL_radioButton->setChecked(true);
        ui->lineEdit_labelStr->setText(labelStr );


    }
    else if(EM_LBLJMP_INSTRUCTION_JMP == selectInstructionFlag)
    {
        ui->JMP_radioButton->setEnabled(true);
        ui->JMP_radioButton->setChecked(true);
        ui->lineEdit_labelStr_jump->setText(labelStr );
        ui->LBLDataType_comboBox->setCurrentIndex(lblDataType);
    }

    else if((EM_LBLJMP_INSTRUCTION_END == selectInstructionFlag)
            || (EM_LBLJMP_INSTRUCTION_PAUSE == selectInstructionFlag)
            || (EM_LBLJMP_INSTRUCTION_ABORT == selectInstructionFlag))
    {
        ui->END_radioButton->setEnabled(true);
        ui->PAUSE_radioButton->setEnabled(true);
        ui->ABORT_radioButton->setEnabled(true);

        if(EM_LBLJMP_INSTRUCTION_END == selectInstructionFlag)
        {
            ui->END_radioButton->setChecked(true);
        }
        else if(EM_LBLJMP_INSTRUCTION_PAUSE == selectInstructionFlag)
        {
            ui->PAUSE_radioButton->setChecked(true);
        }
        else if(EM_LBLJMP_INSTRUCTION_ABORT == selectInstructionFlag)
        {
            ui->ABORT_radioButton->setChecked(true);
        }
    }

    else if((EM_LBLJMP_INSTRUCTION_CALL == selectInstructionFlag)
            || (EM_LBLJMP_INSTRUCTION_RUN == selectInstructionFlag))
    {
        ui->CALL_radioButton->setEnabled(true);
        ui->RUN_radioButton->setEnabled(true);

        if(EM_LBLJMP_INSTRUCTION_CALL == selectInstructionFlag)
        {
            ui->CALL_radioButton->setChecked(true);
        }
        else if(EM_LBLJMP_INSTRUCTION_RUN == selectInstructionFlag)
        {
            ui->RUN_radioButton->setChecked(true);
        }
        ui->CALLProgram_lineEdit->setText(callProgram);

    }



    ui->note_lineEdit->setText(note);
}

void LabelJmpView::getInput()
{
    if(EM_LBLJMP_INSTRUCTION_LBL == selectInstructionFlag)
    {

        labelStr = ui->lineEdit_labelStr->text();
        lblDataType = 0;
    }
    else if(EM_LBLJMP_INSTRUCTION_JMP == selectInstructionFlag)
    {

        labelStr = ui->lineEdit_labelStr_jump->text();
        lblDataType = ui->LBLDataType_comboBox->currentIndex();
    }


    callProgram = ui->CALLProgram_lineEdit->text();

    note = ui->note_lineEdit->text();
}

void LabelJmpView::setProgromFileName(QString fileName)
{
    ui->CALLProgram_lineEdit->setText(fileName);
}

void LabelJmpView::on_LBL_radioButton_clicked()
{
    emit selectLabelInstruction();
}

void LabelJmpView::on_JMP_radioButton_clicked()
{
    emit selectJmpInstruction();
}

void LabelJmpView::on_END_radioButton_clicked()
{
    emit selectEndInstruction();
}

void LabelJmpView::on_PAUSE_radioButton_clicked()
{
    emit selectPauseInstruction();
}

void LabelJmpView::on_ABORT_radioButton_clicked()
{
    emit selectAbortInstruction();
}

void LabelJmpView::on_CALL_radioButton_clicked()
{
    emit selectCallInstruction();
}

void LabelJmpView::on_RUN_radioButton_clicked()
{
    emit selectRunInstruction();
}

void LabelJmpView::on_browse_Btn_clicked()
{
    emit browseCallProgram(ui->CALLProgram_lineEdit->text());
    //progromListView->show();
}

void LabelJmpView::on_clearNote_Btn_clicked()
{
    ui->note_lineEdit->clear();
    emit clearNote();
}

void LabelJmpView::on_forward_Btn_clicked()
{
    this->close();
    programView->instructionListFlag = 0;
    programView->editInstructionViewShowOrHide();
}

void LabelJmpView::on_save_Btn_clicked()
{
    getInput();

    emit finishEditInstruction();
    emit saveInstruction(instruction);
}

void LabelJmpView::changeLanguage(int language)
{
    if(1 == language)
    {
        translator.load("/agvwork/AgvHmi/baseBag/hmiProject/language/labelViewEnglishLan.qm");
        qApp->installTranslator(&translator);
    }
    else
    {
        qApp->removeTranslator(&translator);
    }
    ui->retranslateUi(this);
}
